class Animal{
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(this.name+"正在吃！");
    }
}

class Dog extends Animal{


    public Dog(String name, int age) {
        super(name, age);//alt+回车
    }

    public void bark(){
        System.out.println(this.name+"汪汪叫！");
    }

    @Override
    public void eat(){
        System.out.println(this.name+"正在吃狗粮！");
    }
}

class Bird extends Animal{
    public Bird(String name, int age) {
        super(name, age);
    }

    public void qiqi(){
        System.out.println(this.name+"吱吱叫！");
    }

    public void fly(){
        System.out.println(this.name+"正在飞");
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃鸟粮");
    }
}


class Teacher{

}

class Student{

}

class School{
    private Teacher[] teacher;
    private Student[] students;
}


public class test0 {

    public static void main(String[] args) {
        Animal animal1=new Dog("小黄",10);
        //向下转型不安全
        if(animal1 instanceof Bird){//加上这个if
            Bird bird2=(Bird) animal1;
            bird2.fly();
        }else{
            System.out.println("animal1 instanceof Bird not");
        }

        Dog dog=(Dog) animal1;
        dog.bark();

        System.out.println("==========");

        Animal animal2=new Bird("小黄",10);
        Bird bird=(Bird)animal2;
        bird.fly();
        System.out.println("=========");

    }

    public static Animal func2(){
        return new Dog("小黄",10);
    }

    public static void func(Animal animal1){
        animal1.eat();
    }

    public static void main2(String[] args) {
        Dog dog=new Dog("小黄",10);
        Bird bird=new Bird("小鸟",10);
        //向上转型
        func(dog);
        func(bird);
    }


    public static void main1(String[] args) {
       /* Dog dog=new Dog();
        Animal animal=dog;//向上转型  子类对象给到父类*/
        Animal animal1=new Dog("小黄",10);
        animal1.eat();
        //animal1.bark();报错 是因为Animal当中没有这个bark方法
        //通过父类引用 访问的时候 只能访问父类自己特有的
    }
}
